package etxt2db.features;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import edu.cmu.minorthird.text.MutableTextLabels;
import edu.cmu.minorthird.text.Span;
import etxt2db.corpus.CompleteTextLabels;

public class ClassifiedDocumentFeatureClassifier extends CharacterFeatureClassifier implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2553433177997880403L;
	String type;
	
	public ClassifiedDocumentFeatureClassifier(String type) {
		this.type = type;
	}
	
	public List<String> emit(String text) {
		MutableTextLabels completeLabels = ((CompleteTextLabels)corpus).getSecondaryLabels();
		
		List<String> result = new ArrayList<String>();
		
		Iterator<Span> iter = completeLabels.getTextBase().documentSpanIterator();
		while(iter.hasNext()){
			Span current = iter.next();
			Set<Span> annotatedSpans = completeLabels.getTypeSet(type, current.getDocumentId());
			for(Span span : annotatedSpans){
				if(span.contains(this.span)){
					result.add("AnnotatedDocument=" + type);
				}
			}
		}
		
		return result;
	}

}
